// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.1

package file

import (
	"audio-server/internal/model"
	"context"

	"audio-server/internal/svc"
	"audio-server/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type FileUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewFileUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FileUpdateLogic {
	return &FileUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *FileUpdateLogic) FileUpdate(req *types.FileUpdateReq) (resp *types.BaseMsgResp, err error) {
	// todo: add your logic here and delete this line
	id := req.FileId
	name := req.Name

	fileModel := model.NewSysFileModel(l.svcCtx.Conn)

	file, err := fileModel.FindOne(l.ctx, id)
	if err != nil {
		return &types.BaseMsgResp{
			Code: 500,
			Msg:  "文件不存在",
		}, err
	}

	file.Name = name
	err = fileModel.Update(l.ctx, file)
	if err != nil {
		return &types.BaseMsgResp{
			Code: 500,
			Msg:  "更新文件失败",
		}, err
	}

	return &types.BaseMsgResp{
		Code: 200,
		Msg:  "更新文件成功",
	}, nil
}
